package com.smartEdu.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.smartEdu.commons.LogCvt;
import com.smartEdu.commons.Session;
import com.smartEdu.commons.Tag_Tips;
import com.smartEdu.dao.UserDao;
import com.smartEdu.mapper.UserMapper;
import com.smartEdu.model.UserModel;
import com.smartEdu.module.schedule.CourseInquiry;
import com.smartEdu.module.schedule.Login;
import com.smartEdu.utils.ToolUtils;
import com.smartEdu.vo.UserInfoVo;

@Service
public class UserService {
	@Autowired
	private UserMapper userMapper;
	@Autowired
	@Qualifier(value="userDaoImpl")
	private UserDao userDao;
	
	public List<UserModel> getAllUser(){
		return userDao.getAllUser();
	}
	
	public List<UserModel> getAllUserTeacher(){
		return userDao.getAllUserTeacher();
	}
	
	public void checkUserInfo(Session sess, String loginname, String passwd) {
		String sid = userMapper.checkLoginAuth(loginname, ToolUtils.MD5(passwd).toLowerCase());
		UserInfoVo vo = null;
		if (sid == null || "".equals(sid)) {// 初次登录
			
		}
		else {
			vo = userDao.getUserInfo(loginname);
		}
		//验证账号正确性
		Login lg = new Login();
		if (lg.loginAuth(loginname,passwd)) {
			try {
				CourseInquiry cs = new CourseInquiry();
				sess.put("schedule", cs.queryStuCourse("2016-2017-2"));
				sess.put(Tag_Tips.RESPCODE,Tag_Tips.OK);
				sess.put("userinfo", vo);
			} catch (Exception e) {
				sess.put(Tag_Tips.RESPCODE,Tag_Tips.ERROR);
				LogCvt.error("账号密码错误",e);
			}
		}
		else {
			sess.put(Tag_Tips.RESPCODE,Tag_Tips.ERROR);
			sess.put(Tag_Tips.RESPMSG,"账号密码错误");
		}
	}
}
